<?php

 class AuthUtility
 {
 	const PASSWORD_SALT = '!v1llburd5!';
	const NOPASS = '!NOTAPassword^*!';
	
	/**
	 * Hash a password 
	 *
	 * @param string $password
	 * @return string
	 */
	public static function hashPassword($password)
	{
		//remove salt to make the passwords compatible with CR..
		return md5($password);
		
	}	
	
	public static function getCurrentPayer()
	{
		Zend_Loader::loadClass("Payer");
		
		$auth = BaseAuth::getInstance();
		$userId = $auth->id;
		
		$payer = new Payer();
		$payerData = null;
		if ($payer->loadByUserID($userId)){
			$payerData = $payer->toArray();
		}
		
		return $payerData;
	}
	
	public static function getCurrentUserId()
	{
		$auth = BaseAuth::getInstance();
		return $auth->id;
	}
	
	public static function getCurrentCcKey()
	{
		$auth = BaseAuth::getInstance();
		return $auth->cc_key;
	}
	
	public static function getCurrentUserEmail(){
	
		Zend_Loader::loadClass("UserType");
		Zend_Loader::loadClass("CodesUtility");
		$auth = BaseAuth::getInstance();
		
		$userType = new UserType();
		$userType->loadWhere("id = ". $auth->user_type_id );
		
		if($userType->code == CodesUtility::USER_TYPE_ADMIN || $userType->code == CodesUtility::USER_TYPE_SUPER_USER ) {

			Zend_Loader::loadClass("Administrator");
			$admin = new Administrator();
			$admin->loadWhere("user_id = ". $auth->id);
			
			return $admin->email;
		} elseif($userType->code == CodesUtility::USER_TYPE_STAFF ) {
			Zend_Loader::loadClass("Staff");
			Zend_Loader::loadClass("StaffContact");
			Zend_Loader::loadClass("ContactType");
			
			$contactType= new ContactType();
			$staff = new Staff();
			$staffContact = new StaffContact();
			
			$contactType->loadWhere("code = '". CodesUtility::CONTACT_TYPE_EMAIL . "'");
			
			$staff->loadWhere("user_id = ". $auth->id);
			$staffContact->loadWhere(" id = ". $staff->id . " and contact_type_id ".  $cotactType->id);
			return $staffContact->value;
			
		} else {
			Zend_Loader::loadClass("Payer");
			$payer = new Payer();
			$payer->loadWhere("user_id = ". $auth->id);
			$id = $payer->id;
			$payer->clear();
			$payerValue = $payer->getPayerEmail($id);
			return $payerValue[0]['email'];
		}
		
		
		
	}
	
 }
?>
